<script>
	const httpRequest = require("@/common/httpRequest.js")
	import WebSocket from '@/common/websocket.js' //websocket封装
	export default {
		data() {
			return {
				websocket: null,
				yinpinSetall: {}
			}
		},
		globalData: {
			zslxlist: [{
					name: '休息',
					value: "2"
				},
				{
					name: '住宿',
					value: "1"
				}, {
					name: '車泊',
					value: "4"
				},
				{
					name: '搭帳',
					value: "5"
				},
				{
					name: '夜衝',
					value: "3"
				}
			]
		},
		onLaunch: function() {
			uni.$on("fuwulingfn", data => {
				httpRequest.modal('服務鈴', data, false, (resp) => {})
				this.scanAudiofuwu()
			})
			uni.$on("newshangpinfn", data => { //新商品訂單
				httpRequest.modal('新商品訂單', "您有一個商品訂單，請及時處理", false, (resp) => {})
				this.scanAudiosp()
			})
			uni.$on("newhujiaofn", data => { //新呼叫訂單
				httpRequest.modal('新呼叫訂單', "您有一個新訂單，請及時處理", false, (resp) => {})
				this.scanAudiohj()
			})
			uni.$on("newyuyuefn", data => { //新預約訂單
				httpRequest.modal('新預約訂單', "您有一個預約訂單，請及時處理", false, (resp) => {})
				this.scanAudioyy()
			})
			uni.$on("ubserorderfn", data => { //其他平臺的訂單
				console.log("google平臺的訂單！！！！！！！！", data);
				this.getuberOrderInfo(data)
			})

			this.getplayAudio()
		},
		onShow: function() {
			if (httpRequest.checkIsLogin()) { //已经登陆,创建websocket连接
				this.websocketStart()
				this.setshop()
			}
		},
		onUnload() {
			uni.$off("fuwulingfn")
			uni.$off("newshangpinfn")
			uni.$off("newhujiaofn")
			uni.$off("newyuyuefn")
			this.websocket.close()
		},
		methods: {
			getuberOrderInfo(uber_id) {
				httpRequest.request("/api/Ubercl/uberOrderInfo", "POST", {
					uber_id
				}).then(res => {
					this.$popup.show({
						data: res.data,
						uber_id,
						confirm: () => {
							console.log('点击确定');
						}
					})
				})
			},
			// useradmin.opos.tw/api/ordermake/callUsergetgood
			// ordergoods=下單提醒  ordermake_add=预约下單   ordercall=呼叫订單  ordermake_join=预约呼叫入座  getgood=取餐
			getplayAudio() {
				httpRequest.request("/api/index/getConfigInfoItem", "POST", {
					pidtype: "yinpinset",
				}).then(res => {
					this.yinpinSetall = res.data
				})
			},
			scanAudiofuwu() {
				let music = null
				music = uni.createInnerAudioContext(); //创建播放器对象
				music.sessionCategory = "ambient"
				music.src = require("@/static/fuwul.mp3");
				music.play()
				music.onEnded(() => {
					music = null
				})
			},
			scanAudiosp() { //商品訂單
				let music = null
				music = uni.createInnerAudioContext(); //创建播放器对象
				music.sessionCategory = "ambient"
				// music.src = require("@/static/shangpinorder.mp3");
				music.src = this.yinpinSetall.ordergoods
				music.play()
				music.onEnded(() => {
					music = null
				})
			},
			scanAudiohj() { //呼叫訂單
				let music = null
				music = uni.createInnerAudioContext(); //创建播放器对象
				music.sessionCategory = "ambient"
				// music.src = require("@/static/hujiaoorder.mp3");
				music.src = this.yinpinSetall.ordercall
				music.play()
				music.onEnded(() => {
					music = null
				})
			},
			scanAudioyy() { //預約訂單
				let music = null
				music = uni.createInnerAudioContext(); //创建播放器对象
				music.sessionCategory = "ambient"
				// music.src = require("@/static/yuyueorder.mp3");
				music.src = this.yinpinSetall.ordermake_add
				music.play()
				music.onEnded(() => {
					music = null
				})
			},
			setshop() { //更新商家端登录的状态
				let data = {
					shop_id: uni.getStorageSync("shop_id"),
					hytime: Number(new Date()) / 1000, //商家名称
				}
				httpRequest.request("/api/shop/Shopedit", "POST", data).then(res => {})
			},
			websocketStart() {
				this.websocket = new WebSocket("wss://useradmin.opos.tw:8282");
				this.websocket.connect()
				this.websocket.onMessage(result => {
					console.log('app.js收到服務器内容：' + result.data);
					uni.$emit('updatechatFnte', "")
					uni.$emit('updatechatFnteList', "")
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "colorui/main.css";
	@import "colorui/icon.css";
	@import "uview-ui/index.scss";
	/*每個页面公共css */
	@import url("static/main.css");
	.copyimg{
		background-image: url("@/static/image/workbench/copy.png");
		background-repeat: no-repeat;
		width: 40rpx;
		height: 40rpx;
		min-width: 40rpx;
		background-size: 100%;
	}
	.uni-modal__bd {
		color: #333 !important;
	}
	.weikai {
		border-radius: 0 10rpx 0 10rpx;
		background-color: rgba(153, 153, 153, .1);
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999;
		padding: 5rpx 30rpx;
	}
	
	.yikai {
		border-radius: 0 10rpx 0 10rpx;
		background-color: #50a6a3;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #fff;
		padding: 5rpx 30rpx;
	}
	.weikailist {
		border-radius: 10rpx;
		background-color: rgba(153, 153, 153, .1);
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999;
		padding: 5rpx 10rpx;
	}
	
	.yikailist {
		border-radius: 10rpx;
		background-color: #50a6a3;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #fff;
		padding: 5rpx 10rpx;
	}

	.baisebj {
		box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
		background-color: #ffeab2;
		border-radius: 20rpx 20rpx 0 0;
		padding: 20rpx 15rpx !important;
		color: #333;
	}
	.huangsebj {
		border-radius: 20rpx 20rpx 0 0;
	}
	.saleLableclass {
		padding: 5rpx 30rpx;
		background: rgba(255, 133, 5, 0.1);
		border-radius: 0rpx 14rpx 0rpx 14rpx;
		position: absolute;
		top: 0;
		right: 0;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF8505;
	}
	.shadow{
		box-shadow: 6rpx 6rpx 8rpx rgba(26, 26, 26, 0.04);
	}
	.toprightbtn {
		background-color: #FFB800;
		color: #333;
		font-size: 24rpx;
		font-weight: 900;
		padding: 10rpx 20rpx;
		border-radius: 10rpx;
		letter-spacing: 3rpx;
	}

	

	.shanghuax {
		border-top: 2rpx dashed #333;
	}

	.google_translate_element {
		display: none !important;
	}

	::v-deep.u-radio-group {
		flex-wrap: wrap !important;
	}

	.uni-modal__title {
		color: #00a0e8 !important;
	}

	.guigek {
		background-color: #31a3d6;
		color: #fff;
		border-radius: 10rpx;
		padding: 5rpx 10rpx;
		font-size: 20rpx;
	}

	.dashedline {
		padding-top: 10rpx;
		border-top: 2rpx dashed #333;
	}

	.bold {
		font-weight: bold;
	}

	.mainpadding2s {
		padding: 10rpx;
	}

	.picker-view {
		width: 550rpx;
		height: 600rpx;
		margin-top: 20rpx;
	}

	.item {
		line-height: 100rpx;
		text-align: center;
	}

	.listleftimg {
		width: 157rpx;
		height: 157rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.lan_text {
		color: #24acf2;
	}

	.justify_between_column {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.dingwei {
		position: relative;
	}

	.checkfocus {
		background-color: #ffb800;
		border-radius: 0 20rpx;
		position: absolute;
		top: 0;
		right: 0;
		padding: 5rpx 30rpx;
	}

	.ysdel {
		position: absolute;
		top: 3rpx;
		right: 0;
		padding: 5rpx 30rpx;
	}

	.padding_top1 {
		padding-top: 10rpx;
	}

	.padding_top2 {
		padding-top: 20rpx;
	}

	.padding_top3 {
		padding-top: 30rpx;
	}

	.padding_top15 {
		padding-top: 15rpx;
	}

	.padding_left3 {
		padding-left: 30rpx;
	}

	.padding_left2 {
		padding-left: 20rpx;
	}

	.padding_left1 {
		padding-left: 10rpx;
	}

	.padding_right3 {
		padding-left: 30rpx;
	}

	.padding_right2 {
		padding-left: 20rpx;
	}

	.padding_right1 {
		margin-left: 10rpx;
	}

	.shopPhone {
		width: 60rpx;
		min-width: 60rpx;
		height: 60rpx;
	}

	.line_bottom {
		border-bottom: 2rpx solid rgba(0, 0, 0, 0.05);
	}

	.line_top {
		border-top: 2rpx solid rgba(0, 0, 0, 0.05);
	}

	.xuanzhongs {
		background-image: url("@/static/image/system/xuanzhong.png");
		width: 30rpx;
		min-width: 30rpx;
		height: 30rpx;
		background-size: 100% 100%;
	}

	.wiexuanzhongs {
		background-image: url("@/static/image/system/wiexuanzhong.png");
		width: 30rpx;
		min-width: 30rpx;
		height: 30rpx;
		background-size: 100% 100%;
	}

	.boxshadow {
		box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.1);
	}

	.xiaolan {
		color: #31a3d6;
	}

	.lanlable {
		background-color: #31a3d6;
		border-radius: 50rpx;
		color: #fff;
		padding: 5rpx 15rpx;
	}
</style>